package com.erp.user.controller;

import com.erp.common.constant.Constant;
import com.erp.common.response.BaseResponse;
import com.erp.user.request.*;
import com.erp.user.response.*;
import com.erp.user.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.erp.common.response.ListVo;

import java.util.List;

/**
 * @author shensong
 * @program machining_system.v1.0.0
 * @description 前端控制器
 * @date 2022/12/21 10:51:48
 */

@RestController
@RequestMapping(Constant.API_PREFIX+"/roles")
public class RolesController {

    @Autowired
    private RolesService rolesService;

    /**
    * 分页查询
    */
    @PostMapping("/index")
    public BaseResponse<ListVo<List<RolesInfoResp>>> index(@RequestBody @Validated RolesPageReq request) {
        return BaseResponse.success(rolesService.index(request));
    }

    /**
    * 保存
    */
    @PostMapping("/store")
    public BaseResponse<Boolean> store(@RequestBody @Validated RolesAddReq request) {
        return BaseResponse.success(rolesService.store(request));
    }


    /**
     * 修改
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> update(@RequestBody @Validated RolesUpdateReq request) {
        return BaseResponse.success(rolesService.update(request));
    }

    /**
     * 删除
     */
    @PostMapping("/destroy")
    public BaseResponse<Boolean> destroy(@RequestBody @Validated RolesDeleteReq request) {
        return BaseResponse.success(rolesService.destroy(request));
    }

    /**
     * 审核
     */
    @PostMapping("/approve")
    public BaseResponse<Boolean> approve(@RequestBody @Validated RolesApproveReq request) {
        return BaseResponse.success(rolesService.approve(request));
    }

    /**
     * 启用禁用
     */
    @PostMapping("/enabled")
    public BaseResponse<Boolean> enabled(@RequestBody @Validated RolesStatusReq request) {
        return BaseResponse.success(rolesService.enabled(request));
    }

    /**
     * 详情信息
     */
    @PostMapping("/show")
    public BaseResponse<RolesInfoResp> show(@RequestBody @Validated RolesInfoReq request) {
        return BaseResponse.success(rolesService.show(request));
    }

    /**
     * 列表
     */
    @PostMapping("/option")
    public BaseResponse<List<RolesInfoResp>> option(@RequestBody @Validated RolesListReq request) {
        return BaseResponse.success(rolesService.option(request));
    }

    /**
    * 详情信息
    */
    @PostMapping("/detail")
    public BaseResponse<RolesInfoResp> detail(@RequestBody @Validated RolesInfoReq request) {
        return BaseResponse.success(rolesService.show(request));
    }

    /**
     * 搜索
     */
    @PostMapping("/search")
    public BaseResponse<List<RolesSearchInfoResp>> search(@RequestBody @Validated RolesSearchReq request) {
        return BaseResponse.success(rolesService.search(request));
    }

}
